home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_5 / issue_06 / benchmarks / c_source / ack next >
Encoding:
Text File  |  1991-05-01  |  1006 b   |  54 lines

  1. /* Ackermann benchmark */
  2.  
  3. /* See Software Practice and Experience, Vol 7  pp317-329 (1977)  */
  4.  
  5. #include <time2.h>
  6. #include <stdio.h>
  7.  
  8. #define TRUE 1
  9. #define FALSE 0
  10.  
  11. int main(void)
  12. {
  13. clock_t start, end;
  14. int   i, j, k, k1;
  15. int   failed;
  16.  
  17.    start=clock(); /*gets system time*/
  18.    k = 16;
  19.    k1 = 1;
  20.    failed = FALSE;
  21.    for ( i = 1;i <= 6; i++){
  22.         j = ackermann( 3, i);
  23.         if ( j != k - 3 )
  24.           failed = TRUE;
  25.  
  26.         printf(" NO OF CALLS: %8.0f\n", (512.0*k1 - 15.0*k + 9.0*i + 37.0) / 3.0);
  27.  
  28.         k1 = 4 * k1;
  29.         k = 2 * k ;
  30.    }; /* for */
  31.  
  32.    end=clock();
  33.  
  34.    if ( failed )
  35.       printf(" FAIL \n");
  36.    else
  37.       printf(" PASS \n");
  38.       printf("The timing for this ACKERMANN test was: %f\n", (end-start) / CLK_TCK);
  39.       return 0 ;
  40.  
  41.       };
  42. /* end of main program */
  43.  
  44. ackermann(m, n)
  45. int m,n;
  46. {
  47.     if ( m == 0 )
  48.       return n + 1;
  49.     else if ( n == 0 )
  50.       return ackermann(m - 1, 1);
  51.     else
  52.       return ackermann(m - 1, ackermann(m, n - 1));
  53. } /* ackermann */
  54.